package reflectCus;

import java.io.File;
import java.io.FileFilter;
import java.io.FilenameFilter;
import java.lang.reflect.Method;
import java.util.Arrays;

//含s的无参方法
public class Test3 {
    public static void main(String[] args) throws Exception {
        File f=new File(Test2.class.getResource(".").toURI());
        System.out.println(f);
        String packageName=Test2.class.getPackage().getName();
        String p=".class";

        String[] strings = f.list((o1,o2)->o2.endsWith(p));
        System.out.println(Arrays.toString(strings));
        for (String s:strings
        ) {
            if(s.endsWith(".class")){
                int lastIndex= s.lastIndexOf(".");
                String line=s.substring(0,lastIndex);
                System.out.println(line);
                Class cls=Class.forName(packageName+"."+line);
                Object o=cls.newInstance();
                Method[] methods=cls.getDeclaredMethods();
                for (Method m:methods
                     ) {
                    if(m.getName().contains("s") &&m.getParameterCount()==0 ){
                        m.setAccessible(true);
                        m.invoke(o);
                    }
                }
                System.out.println(o);
            }
        }
    }
}
